import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../config/config.dart';
import '../../../global/global_data.dart';
import '../../../routers/routers.dart';
import '../../../views/common_widget.dart';
import 'select_wifi_logic.dart';

class SelectWifiPage extends StatelessWidget {
  SelectWifiPage({super.key});

  final logic = Get.find<SelectWifiLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg,
      resizeToAvoidBottomInset: false,
      body: Column(
        children: [
          CommonWidget.commonAppBar("选择设备工作WIFI"),
          //选择WIFI
          Obx(
            () => Visibility(
              visible: global.deviceLinkState.value == 0,
              child: Expanded(
                child: Column(
                  children: [
                    Container(
                      width: Get.width,
                      margin: EdgeInsets.only(left: 35.w, right: 35.w, top: 30.w),
                      padding: EdgeInsets.symmetric(vertical: 0.w, horizontal: 35.w),
                      decoration: BoxDecoration(
                        color: Config.colorBg2,
                        borderRadius: BorderRadius.circular(Config.roundBig.w),
                      ),
                      child: Column(
                        children: [
                          SizedBox(
                            height: 110.w,
                            child: Row(
                              children: [
                                Icon(
                                  Icons.wifi,
                                  size: 34.w,
                                  color: Config.colorText1,
                                ),
                                SizedBox(
                                  width: 20.w,
                                ),
                                Text(
                                  "1702-KeTing",
                                  style: TextStyle(
                                      color: Config.colorText1,
                                      fontSize: Config.textSizeContent.sp),
                                ),
                                SizedBox(
                                  width: 20.w,
                                ),
                                Expanded(
                                    child: Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                  children: [
                                    Text(
                                      "更换网络",
                                      style: TextStyle(
                                          color: Config.colorText3,
                                          fontSize: Config.textSizeInfo.sp),
                                    ),
                                    SizedBox(
                                      width: 5.w,
                                    ),
                                    Icon(
                                      Icons.arrow_forward_ios_rounded,
                                      color: Config.colorText3.withOpacity(0.7),
                                      size: 30.w,
                                    ),
                                  ],
                                )),
                              ],
                            ),
                          ),
                          CommonWidget.commonDivider(),
                          SizedBox(
                            height: 110.w,
                            child: Row(
                              children: [
                                Icon(
                                  Icons.lock_outline_rounded,
                                  size: 34.w,
                                  color: Config.colorText1,
                                ),
                                SizedBox(
                                  width: 20.w,
                                ),
                                Expanded(
                                  child: TextField(
                                    keyboardType: TextInputType.phone,
                                    textAlign: TextAlign.left,
                                    maxLength: 11,
                                    maxLines: 1,
                                    cursorColor: Config.colorMain,
                                    onChanged: (value) {},
                                    onTap: () {},
                                    enabled: true,
                                    // controller: controller,
                                    style: TextStyle(
                                        fontSize: Config.textSizeContent.sp,
                                        color: Config.colorText1),
                                    decoration: InputDecoration(
                                      isDense: true,
                                      // 紧凑模式
                                      hintText: "输入wifi密码",
                                      counterText: '',
                                      hintStyle: TextStyle(
                                          fontSize: Config.textSizeContent.sp,
                                          color: Config.colorText3),
                                      border: InputBorder.none,
                                      filled: false,
                                      prefixIcon: null,
                                      contentPadding:
                                          EdgeInsets.symmetric(vertical: 0.w, horizontal: 0.w),
                                    ),
                                  ),
                                ),
                                // Icon(Icons.remove_red_eye_rounded,size: 34.w,color: Config.colorText3,),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 42.w, right: 42.w, top: 25.w),
                      padding: EdgeInsets.symmetric(vertical: 0.w, horizontal: 0.w),
                      child: Text(
                        'CatGuard将会搜索出附近所有的WIFI(2.4G)，用户选择要连接的WIFI名称并输入对应的密码，然后点击连接即可。',
                        style:
                            TextStyle(color: Config.colorText2, fontSize: Config.textSizeInfo.sp),
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          CommonWidget.commonButton("连接", () {
                            logic.connectWifi();
                          }, width: 650.w, radius: 50.w),
                          SizedBox(height: 120.w)
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          //配网成功
          Obx(
            () => Visibility(
              visible:global.deviceLinkState.value == 2,
              child: Expanded(
                child: Column(
                  children: [
                    Container(
                      width: Get.width,
                      margin: EdgeInsets.only(left: 35.w, right: 35.w, top: 30.w),
                      padding: EdgeInsets.symmetric(vertical: 0.w, horizontal: 35.w),
                      decoration: BoxDecoration(
                        color: Config.colorBg2,
                        borderRadius: BorderRadius.circular(Config.roundBig.w),
                      ),
                      child: Column(
                        children: [
                          SizedBox(height: 20.w,),
                          Icon(
                            Icons.download_done_rounded,
                            size: 200.w,
                            color: Config.colorMain,
                          ),
                          Text(
                            '添加成功\n开始体验智能养猫服务吧',
                            textAlign: TextAlign.center,
                            style:
                            TextStyle(color: Config.colorText3, fontSize: Config.textSizeInfo.sp),
                          ),
                          SizedBox(height: 50.w,),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          CommonWidget.commonButton("开始体验", () {
                            Get.back();
                          }, width: 650.w, radius: 50.w),
                          SizedBox(height: 120.w)
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
          //配网失败
          Obx(
                () => Visibility(
              visible:global.deviceLinkState.value == 3,
              child: Expanded(
                child: Column(
                  children: [
                    Container(
                      width: Get.width,
                      margin: EdgeInsets.only(left: 35.w, right: 35.w, top: 30.w),
                      padding: EdgeInsets.symmetric(vertical: 0.w, horizontal: 35.w),
                      decoration: BoxDecoration(
                        color: Config.colorBg2,
                        borderRadius: BorderRadius.circular(Config.roundBig.w),
                      ),
                      child: Column(
                        children: [
                          SizedBox(height: 30.w,),
                          Icon(
                            Icons.error_outline_rounded,
                            size: 200.w,
                            color: Config.colorText3.withOpacity(0.6),
                          ),
                          SizedBox(height: 15.w,),
                          Text(
                            '设备配网失败，请确认设备处于网络配置中\n或者检查wifi密码是否正确',
                            textAlign: TextAlign.center,
                            style:
                            TextStyle(color: Config.colorText3, fontSize: Config.textSizeInfo.sp),
                          ),
                          SizedBox(height: 50.w,),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          CommonWidget.commonButton("重新搜索", () {
                            Get.back();
                          }, width: 650.w, radius: 50.w),
                          SizedBox(height: 120.w)
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
